<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>水毁抢修</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/buttons.css" />
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-form.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/datagrid-detailview.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/util/jquery.cookie.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/YMLib.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/YWLib.js"></script>
	<style type="text/css">
		.table{border: 1px solid #FFE7BA;}
		.table tr{border: 1px solid #FFE7BA;}
		.table tr td{border: 1px solid #FFE7BA;}
		.table tr td input{width: 50px;}
	</style>
	<style type="text/css">
		.table1{border: 1px solid #FFE7BA;}
		.table1 tr{border: 1px solid #FFE7BA;}
		.table1 tr td{border: 1px solid #FFE7BA;}
	</style>
	<script type="text/javascript">
		function loadWhBmbmShNew(id, xmnf) {
			$('#' + id).combobox({
				url : '/jxcsxm/xtgl/getWhTreeByNameShNew.do?xmnf='
						+ xmnf + '&gydwbm=21101360000',
				valueField : 'bmid',
				textField : 'name',
				panelHeight:'auto',
				editable:false,
				multiple:false
			});
		}
		$(function(){
			$("#nf1").combobox({onSelect:function(record){
				loadWhBmbmShNew('jhxdwh', $("#nf1").combobox('getValue'));
				// loadWhBmbmSh('jhxdwh',$("#nf1").combobox('getValue')+"21101360000");
			}})
			/* $("#nf").combobox({onSelect:function(record){
				loadZj($.cookie("unit"));
				
				loadWhBmbmSh('jhxdwh',$("#nf").combobox('getValue')+"21101360000");
			}})
			$("#yf").combobox({onSelect:function(record){
				loadZj($.cookie("unit"));
			}}) */
			//loadBmbm('bd','标段');
			
			loadBmbm('nf1','项目年份',new Date().getFullYear());
			
			getFwqTime("bfyf");
			var yf=new Date().getMonth()+1;
			var day=new Date().getDate();
			if(yf<10) yf='0'+yf;
			if(day<10) day='0'+day;
			loadWhBmbmShNew('jhxdwh', $("#nf1").combobox('getValue'));
			// loadWhBmbmSh('jhxdwh',new Date().getFullYear()+"21101360000");
			
			var gydw=$.cookie("unit");
			if(gydw=="36"){
				loadChildGydw("21101360000");
				//loadChildGydw("11101360000");
			}else{
				loadChildGydw(gydw);
			}
			
		});
		function search(){
			
			loadZj($.cookie("unit"));
			loadxddw($.cookie("unit"));
		}
		function loadChildGydw(gydw){
			$.ajax({
				type:'post',
				async:false,
				url:'/jxcsxm/zjdw/queryChildGydw.do',
				data:'gydw='+gydw,
				dataType:'json',
				success:function(data){
					$.each(data,function(index,item){
						$('#zjbf_table_tbody').append('<tr name="'+$.cookie("unit")+'" id="'+item.id+'"><td align="center">'+item.name+'</td><td align="center"><input type="number" width="60" /><font color="red"></font></td><td  align="center"><input type="number" width="60" /><font color="red"></font></td><td  align="center"><input type="number" width="60" /><font color="red"></font></td><td  align="center"><input type="number" readonly width="60" /><font color="red"></font><input type="hidden" value="'+item.parent+'"/></td><td align="center"><input oninput="sumDfzc()" type="number" width="60" /><font color="red"></font></td><td align="center"><input oninput="sumDfzc()" type="number" width="60" /><font color="red"></font></td><td align="center"><input oninput="sumDfzc()" type="number" width="60" /><font color="red"></font></td></tr>');
					});
				}
			});
			
			loadZj($.cookie("unit"));
		}

		function sumDfzc(){
			var tr = $("tr[name='"+$.cookie("unit")+"']");
			$.each(tr,function(index,item){
				var inputList = $("#"+item.id+" input");
				var dszc1=0;var qxzc1=0;var qtzc1=0;
				// dfzc1=$(inputList[3]).val()==""?0:$(inputList[3]).val();
				dszc1=parseFloat($(inputList[5]).val()==""?0:$(inputList[5]).val());
				qxzc1=parseFloat($(inputList[6]).val()==""?0:$(inputList[6]).val());
				qtzc1=parseFloat($(inputList[7]).val()==""?0:$(inputList[7]).val());
				$(inputList[3]).val(dszc1+qxzc1+qtzc1);
			});

			// $('#dfzc').val(parseFloat($('#dszc').val() === "" ?0:$('#dszc').val())
			// 		+parseFloat($('#qxzc').val() === "" ?0:$('#qxzc').val())
			// 		+parseFloat($('#qtzc').val() === "" ?0:$('#qtzc').val()) );

		}
		function loadZj(gydwdm){
			
			var zjq;
			if($.cookie("unit")=="36")
			zj={'gydwdm':"21101360000",'bfyf':$("#bfyf").combo('getValue'),'nf':$("#nf1").combo('getValue'),'jhxdwh':$("#jhxdwh").combo('getValue')};
			else zj={'gydwdm':$.cookie('unit'),'bfyf':$("#bfyf").combo('getValue'),'nf':$("#nf1").combo('getValue'),'jhxdwh':$("#jhxdwh").combo('getValue')};
			$.ajax({
				type:'post',
				async:false,
				url:'/jxcsxm/zjbf/queryZjByGydwdm.do',
				data:zj,
				dataType:'json',
				success:function(data){
					if(data.length>0){
						$.each(data,function(index,item){
							var input=$("#"+item.gydwdm+" input");
							$(input[0]).val(item.cgs);
							$(input[1]).val(item.rys);
							$(input[2]).val(item.ttc);
							$(input[3]).val(item.dfzc);
							$(input[4]).val(item.parent);

							$(input[5]).val(item.dszc);
							$(input[6]).val(item.qxzc);
							$(input[7]).val(item.qtzc);
							$("#jhxdwh").combobox('setValue',item.jhxdwh);
							$("#bfyf").combobox('setValue',item.bfyf);
							$("#bd").combobox('setText',item.bd);
							$("#bz").val(item.bz);
							$("#tbr").val(item.tbr);
							$("#tbsj").val(item.tbsj);
						});
					}else{
						var tr = $("tr[name='"+gydwdm+"']");
						$.each(tr,function(index,item){
							var inputList = $("#"+item.id+" input");
							$(inputList[0]).val("");
							$(inputList[1]).val("");
							$(inputList[2]).val("");
							$(inputList[3]).val("");

							$(inputList[5]).val("");
							$(inputList[6]).val("");
							$(inputList[7]).val("");
						});
						$("#tbr").val($.cookie('name'));
						var yf=new Date().getMonth()+1;
						var day=new Date().getDate();
						if(yf<10) yf='0'+yf;
						if(day<10) day='0'+day;
						$("#tbsj").val(new Date().getFullYear()+"-"+yf+"-"+day);
						
					}
				}
			});
		}
		
		function loadxddw(gydwdm){
			
			var zjq;
			if($.cookie("unit")=="36")
			zj={'gydwdm':"21101360000",'bfyf':$("#bfyf").combo('getValue'),'nf':$("#nf1").combo('getValue'),'jhxdwh':$("#jhxdwh").combo('getValue')};
			else zj={'gydwdm':$.cookie('unit'),'bfyf':$("#bfyf").combo('getValue'),'nf':$("#nf1").combo('getValue'),'jhxdwh':$("#jhxdwh").combo('getValue')};
			$.ajax({
				type:'post',
				async:false,
				url:'/jxcsxm/zjbf/queryZjdwbfByGydwdm.do',
				data:zj,
				dataType:'json',
				success:function(data){
					if(data.length>0){
						$.each(data,function(index,item){
							var font=$("#"+item.gydwdm+" font");
							$(font[0]).html("余"+item.cgs);
							$(font[1]).html("余"+item.rys);
							$(font[2]).html("余"+item.ttc);
							$(font[3]).html("余"+item.dfzc);
							
						});
					}
				}
			});
		}
		
		
		function save(){
			if($('#bd').combo("getText")==""){alert("请选择标段");return;}
			
			if($('#jhxdwh').combo("getValue")==""){alert("请选择计划下达文号");return;}
			/* var json_data = JSON.stringify(caiji($.cookie("unit"))); 
			alert(json_data); */
			if ($("#tbr").val() == "" || $("#tbr").val() == null) {
				alert("请填写填报人");
				return;
			}
			
			$.ajax({
				type:'post',
				url:'/jxcsxm/zjbf/insertOrUpdateShqx.do',
				data:params($.cookie("unit")),
				dataType:'json',
				success:function(data){
					alert("保存成功！");
					parent.queryXmlist();
					closeWindow();
				}
			});
			
			
			
		}

		function params(name){
			var zj = {
				gydwdm:"",parent:"",bfyf:"",
				cgs1:"",rys1:"",ttc1:"",
				dfzc1:"",dszc1:"",qxzc1:"",qtzc1:"",
				ztz1:"",bd:"",jhxdwh:"",
				bz:'',nf:"",tbr:"",tbsj:""
			};
			var ztz1=0;var cgs1=0;var rys1=0;
			var ttc1=0;var dfzc1=0;var dszc1=0;
			var qxzc1=0;var qtzc1=0;

			var tr = $("tr[name='"+name+"']");
			$.each(tr,function(index,item){
				var inputList = $("#"+item.id+" input");
				if (index == 0) {
					zj.gydwdm = item.id;
					zj.parent = $(inputList[4]).val();
					zj.bfyf = $("#bfyf").combo('getValue');
					cgs1 = $(inputList[0]).val() == "" || $(inputList[0]).val() == null ?
							0 : parseFloat($(inputList[0]).val()); // 车购税
					rys1 = $(inputList[1]).val() == "" || $(inputList[1]).val() == null ?
							0 : parseFloat($(inputList[1]).val()); // 燃油税
					ttc1 = $(inputList[2]).val() == "" || $(inputList[2]).val() == null ?
							0 : parseFloat($(inputList[2]).val()); // 厅统筹
					dszc1 = $(inputList[7]).val() == "" || $(inputList[7]).val() == null ?
							0 : parseFloat($(inputList[7]).val()); // 地方财政
					qxzc1 = $(inputList[8]).val() == "" || $(inputList[8]).val() == null ?
							0 : parseFloat($(inputList[8]).val()); // 县区财政
					qtzc1 = $(inputList[9]).val() == "" || $(inputList[9]).val() == null ?
							0 : parseFloat($(inputList[9]).val()); // 其他自筹
					dfzc1 = dszc1 + qxzc1 + qtzc1;
					zj.cgs1 = cgs1;zj.rys1 = rys1;zj.ttc1 = ttc1;
					zj.dfzc1 = dfzc1;zj.dszc1 = dszc1;zj.qxzc1 = qxzc1;
					zj.qtzc1 = qtzc1;
					ztz1 = cgs1 + rys1 + ttc1 + dfzc1;
					zj.ztz1 = ztz1;
					zj.bz = $("#bz").val();
					zj.bd = $("#bd").combo('getText');
					zj.jhxdwh = $("#jhxdwh").combo('getValue');
					zj.nf = $("#nf1").combo('getValue');
					zj.tbr = $("#tbr").val();
					zj.tbsj = $("#tbsj").val();
				}
				else {
					zj.gydwdm += "," + item.id;
					zj.parent += "," + $(inputList[4]).val();
					zj.bfyf += "," + $("#bfyf").combo('getValue');
					cgs1 = $(inputList[0]).val() == "" || $(inputList[0]).val() == null ?
							0 : parseFloat($(inputList[0]).val()); // 车购税
					rys1 = $(inputList[1]).val() == "" || $(inputList[1]).val() == null ?
							0 : parseFloat($(inputList[1]).val()); // 燃油税
					ttc1 = $(inputList[2]).val() == "" || $(inputList[2]).val() == null ?
							0 : parseFloat($(inputList[2]).val()); // 厅统筹
					dszc1 = $(inputList[7]).val() == "" || $(inputList[7]).val() == null ?
							0 : parseFloat($(inputList[7]).val()); // 地方财政
					qxzc1 = $(inputList[8]).val() == "" || $(inputList[8]).val() == null ?
							0 : parseFloat($(inputList[8]).val()); // 县区财政
					qtzc1 = $(inputList[9]).val() == "" || $(inputList[9]).val() == null ?
							0 : parseFloat($(inputList[9]).val()); // 其他自筹
					dfzc1 = dszc1 + qxzc1 + qtzc1;
					zj.cgs1 += "," + cgs1;
					zj.rys1 += "," + rys1;
					zj.ttc1 += "," + ttc1;
					zj.dfzc1 += "," + dfzc1;
					zj.dszc1 += "," + dszc1;
					zj.qxzc1 += "," + qxzc1;
					zj.qtzc1 += "," + qtzc1;
					ztz1 = cgs1 + rys1 + ttc1 + dfzc1;
					zj.ztz1 += "," + ztz1;
					zj.bz += "," + $("#bz").val();
					zj.bd += "," + $("#bd").combo('getText');
					zj.jhxdwh += "," + $("#jhxdwh").combo('getValue');
					zj.nf += "," + $("#nf1").combo('getValue');
					zj.tbr += "," + $("#tbr").val();
					zj.tbsj += "," + $("#tbsj").val();
				}
			});
			return zj;
		}

		function caiji(name){
 			var zj = {
 				gydwdm:"",parent:"",bfyf:"",
				cgs1:"",rys1:"",ttc1:"",
				dfzc1:"",dszc1:"",qxzc1:"",qtzc1:"",
				ztz1:"",bd:"",jhxdwh:"",
				bz:'',nf:"",tbr:"",tbsj:""
 			};
			var tr = $("tr[name='"+name+"']");
			 $.each(tr,function(index,item){
				 
				var inputList = $("#"+item.id+" input");
				var ztz1=0;var cgs1=0;var rys1=0;var ttc1=0;var dfzc1=0;var dszc1=0;var qxzc1=0;var qtzc1=0;
				
				if(index==0){
					zj.gydwdm+=item.id;
					zj.parent+=$(inputList[4]).val();
					zj.bfyf+=$("#bfyf").combo('getValue');
					cgs1=$(inputList[0]).val()==""?0:$(inputList[0]).val();
					rys1=$(inputList[1]).val()==""?0:$(inputList[1]).val();
					ttc1=$(inputList[2]).val()==""?0:$(inputList[2]).val();
					// dfzc1=$(inputList[3]).val()==""?0:$(inputList[3]).val();
					dszc1=$(inputList[5]).val()==""?0:$(inputList[5]).val();
					qxzc1=$(inputList[6]).val()==""?0:$(inputList[6]).val();
					qtzc1=$(inputList[7]).val()==""?0:$(inputList[7]).val();
					dfzc1=parseFloat($(inputList[5]).val()==""?0:$(inputList[5]).val())+parseFloat($(inputList[6]).val()==""?0:$(inputList[6]).val())+parseFloat($(inputList[7]).val()==""?0:$(inputList[7]).val());


					zj.cgs1+=cgs1;zj.rys1+=rys1;zj.ttc1+=ttc1;zj.dfzc1+=dfzc1;zj.dszc1+=dszc1;zj.qxzc1+=qxzc1;zj.qtzc1+=qtzc1;
					ztz1=accAdd(ztz1,$(inputList[0]).val()==""?0:$(inputList[0]).val());
					ztz1=accAdd(ztz1,$(inputList[1]).val()==""?0:$(inputList[1]).val());
					ztz1=accAdd(ztz1,$(inputList[2]).val()==""?0:$(inputList[2]).val());
					ztz1=accAdd(ztz1,$(inputList[3]).val()==""?0:$(inputList[3]).val());
					zj.ztz1+=ztz1;
					zj.bd+=$("#bd").combo('getText');
					zj.jhxdwh+=$("#jhxdwh").combo('getValue');
					zj.bz=$("#bz").val();
					zj.nf+=$("#nf1").combo('getValue');
					zj.tbr+=$("#tbr").val();
					zj.tbsj+=$("#tbsj").val();
				}else{
					zj.gydwdm+=","+item.id;
					zj.parent+=","+$(inputList[4]).val();
					zj.bfyf+=","+$("#bfyf").combo('getValue');
					cgs1=$(inputList[0]).val()==""?0:$(inputList[0]).val();
					rys1=$(inputList[1]).val()==""?0:$(inputList[1]).val();
					ttc1=$(inputList[2]).val()==""?0:$(inputList[2]).val();
					// dfzc1=$(inputList[3]).val()==""?0:$(inputList[3]).val();
					dszc1=$(inputList[5]).val()==""?0:$(inputList[5]).val();
					qxzc1=$(inputList[6]).val()==""?0:$(inputList[6]).val();
					qtzc1=$(inputList[7]).val()==""?0:$(inputList[7]).val();
					dfzc1=parseFloat($(inputList[5]).val()==""?0:$(inputList[5]).val())+parseFloat($(inputList[6]).val()==""?0:$(inputList[6]).val())+parseFloat($(inputList[7]).val()==""?0:$(inputList[7]).val());

					zj.cgs1+=","+cgs1;zj.rys1+=","+rys1;zj.ttc1+=","+ttc1;zj.dfzc1+=","+dfzc1;zj.dszc1+=dszc1;zj.qxzc1+=qxzc1;zj.qtzc1+=qtzc1;
					ztz1=accAdd(ztz1,$(inputList[0]).val()==""?0:$(inputList[0]).val());
					ztz1=accAdd(ztz1,$(inputList[1]).val()==""?0:$(inputList[1]).val());
					ztz1=accAdd(ztz1,$(inputList[2]).val()==""?0:$(inputList[2]).val());
					ztz1=accAdd(ztz1,$(inputList[3]).val()==""?0:$(inputList[3]).val());
					zj.ztz1+=","+ztz1;
					zj.bd+=","+$("#bd").combo('getText');
					zj.jhxdwh+=","+$("#jhxdwh").combo('getValue');
					zj.bz+=","+$("#bz").val();
					zj.nf+=","+$("#nf1").combo('getValue');
					zj.tbr+=","+$("#tbr").val();
					zj.tbsj+=","+$("#tbsj").val();
				}
			}); 
			return zj;
		}
	</script>
</head>
<body>
	<div style="text-align: left;font-size: 12px;margin: 0px;width:99%;">
		<table width="99%" border="0" style="margin-top: 1px; margin-left: 1px;" cellspacing="0" cellpadding="0">
			
        	<tr>
        		<td>
        			<div align="center">
        				<table class="table1" cellpadding="0" cellspacing="0" width="800">
        				<tr align='center' height="28">
        						<td width="100">年份</td>
								<td  align="left" style="padding-left: 10px;" width="100">
								<input type="text" class='easyui-combobox' id='nf1' style="width: 125px;">
								<td width="100">计划下达文号</td>
								<td align="left" style="padding-left: 10px;" width="100"><input type='text' id='jhxdwh'style="width: 140px;"></td>
								<td align="center" rowspan="3">
								<input value=" 查询  " onclick="search()" style="text-align: center;" type="button"/><br><font color="red">*选择年份、拨付月份、计划下达文号后点击查询自动计算剩余资金</font>
							</td>
						</tr>
        				
        				<tr align='center' height="28">
        						<td width="100">拨付月份</td>
								<td align="left" style="padding-left: 10px;" width="150"><input type="text" class='easyui-combobox' id='bfyf' style="width: 120px;"></td>
								<td width="100">标段</td>
								<td align="left" style="padding-left: 10px;" width="140"><select id="bd" class='easyui-combobox' style="width: 140px">
								<option value="没有标段" selected="selected">没有标段</option>
								</select>
								
							</tr>
							<tr align='center' height="28">
        						<td width="100">填报人</td>
								<td align="left" style="padding-left: 10px;" width="100">
								<input type="text" id='tbr' style="width: 125px;">
								<td width="100">填报时间</td>
								<td align="left" style="padding-left: 10px;" width="100"><input type='text' class='easyui-datebox' id='tbsj'style="width: 140px;" readonly="readonly"></td>
							</tr>
							<tr align='center' height="28">
        						<td >备注</td>
								<td align="left" style="padding-left: 10px;" colspan="5" style="background-color: #ffffff; height: 20px;" align="left">
									<textarea name="bz" id="bz" rows="2" style="width: 510px;"></textarea>
								</td>
							</tr>
						</table>
						<table id="zjbf_table" width="800" class="table" cellpadding="0" cellspacing="0">
							
							<tr align='center' height="28">
								<td>单位名称</td>
								<td>车购税(万元)</td>
								<td>燃油税(万元)</td>
								<td>厅统筹(万元)</td>
								<td>地方自筹(万元)</td>
								<td>地市财政自筹(万元)</td>
								<td>区县财政自筹(万元)</td>
								<td>其他自筹(万元)</td>
							</tr>
							<tbody id="zjbf_table_tbody"></tbody>
						</table>
						<table width="600">
							<tr align="center">
								<td>
									<input value=" 保  存  " onclick="save()" style="text-align: center;" type="button"/>
								</td>
							</tr>
						</table>
					</div>
				</td>
        	</tr>
		</table>
	</div>
</body>
</html>
